package io.dbw.modules.business.controller.sys;

import io.dbw.common.enums.ResultStatusEnum;
import io.dbw.common.exception.BusinessException;
import io.dbw.common.utils.Constant;
import io.dbw.common.utils.Result;
import io.dbw.modules.business.vo.CommonUserVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;

import java.util.Map;

/**
　* @description: Controller公共组件
　* @author lxc
　* @date 2021/5/7 14:08
*/
@Slf4j
public abstract class AbstractController {


	protected CommonUserVO getUser() {
		CommonUserVO user = (CommonUserVO) SecurityUtils.getSubject().getPrincipal();
		if (user == null) {
			throw new BusinessException(ResultStatusEnum.USER_OVERDUE);
		}
		return user;
	}


	/**
	 * 获取登陆用户信息
	 * @return
	 */
	protected Long getUserId() {
		return getUser().getUserId();
	}
	/**
	 * 执行成功
	 * @param object 需要返回的值
	 * @return
	 */
	public static Result writeSuccess(Object object){
		System.out.println(object);
		return Result.success(object);
	}

	/**
	 * 执行成功
	 * @return
	 */
	public static Result writeSuccess(){
		return Result.success();
	}
	/**
	 * 系统繁忙
	 * @param
	 * @return
	 */
	public static Result writeFail(){
		log.info("fail--返回错误提示:"+ ResultStatusEnum.FAIL.getMsg());
		return Result.fail();
	}

	/**
	 * 操作失败
	 * @param
	 * @return
	 */
	public static Result writeFail(String msg){
		log.info("fail--返回错误提示:"+msg);
		return Result.fail(msg);
	}
	/**
	 * 执行失败
	 * @param object 错误信息
	 * @return
	 */
	public static Result writeError(Object object){
		return Result.error(object);
	}

	public static Result writeInfo(ResultStatusEnum r){
		return  Result.info(r);
	}

	public static Result writeInfo(String code, String msg){
		return Result.info(code,msg,null);
	}
}
